﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QunProject.Common
{
    /// <summary>
    /// 返回的标准JSON数据
    /// </summary>
    public class JsonData
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool success { get; set; }
        /// <summary>
        /// 代码
        /// </summary>
        public int code { get; set; }
        /// <summary>
        /// 消息
        /// </summary>
        public string msg { get; set; }
        /// <summary>
        /// 数据
        /// </summary>
        public object data { get; set; }
        /// <summary>
        /// 实例化一个结果JSON数据 [ false | 1 | message_失败 | null ]
        /// </summary>
        public JsonData()
        {
            success = false;
            code = (int)EnumHelper.ErrorType.message_失败;
            msg = "失败";
            data = null;
        }
        /// <summary>
        /// 设置为成功
        /// </summary>
        /// <param name="_data">返回的数据</param>
        /// <param name="_msg">返回的消息描述</param>
        /// <param name="_code">返回的错误代码</param>
        public void Success(object _data = null, string _msg = "成功", int _code = (int)EnumHelper.ErrorType.success_成功)
        {
            success = true;
            data = _data;
            code = _code;
            msg = _msg;
        }
        /// <summary>
        /// 设置为失败
        /// </summary>
        /// <param name="_msg">返回的消息描述</param>
        /// <param name="_code">返回的错误代码</param>
        public void ErrorMessage(string _msg = "失败", int _code = (int)EnumHelper.ErrorType.message_失败)
        {
            code = _code;
            msg = _msg;
        }
        /// <summary>
        /// 设置为失败
        /// </summary>
        /// <param name="_msg">返回的消息描述</param>
        /// <param name="_code">返回的错误代码</param>
        public void ErrorAlert(string _msg = "失败", int _code = (int)EnumHelper.ErrorType.alert_失败)
        {
            code = _code;
            msg = _msg;
        }
    }
}
